package com.zmm.util.verify;

import com.zmm.common.base.model.Result;
import com.zmm.common.base.model.ResultCode;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author 900045
 * @description:
 * @name BindingResultUtil
 * @date By 2021-07-06 14:43:04
 */
public class BindingResultUtil {


	public static Result paramVerify(BindingResult result){
		Map<String ,String> errors = result.getFieldErrors()
				.stream()
				.collect(Collectors.toMap(FieldError::getField,FieldError::getDefaultMessage));
		return Result.error(ResultCode.METHOD_CALL_PARAMETER_ERROR,errors);
	}
}
